import java.util.Random;
import java.io.*;

/** Class to read the text files "verber.txt", "substantiver.txt" and "adjektiver.txt" using a particular formatting
  * */


public class ReadTextFiles
{
  private String[] strArrayOfVerbs;
  private String[] strArrayOfSubstantives;
  private String[] strArrayEnEllerEt;
  private String[] strArrayOfAdjectives;
  private String fileNameOfVerbs;
  private String fileNameOfSubstantives;
  private String fileNameOfAdjectives;
  
  
  public ReadTextFiles()
  {
    fileNameOfVerbs = "verber.txt";
    fileNameOfSubstantives = "substantiver.txt";
    fileNameOfAdjectives = "adjektiver.txt";
    
    readVerbsFromFile();
    readSubstantivesFromFile();
    readAdjectivesFromFile();

  }
  
 /** Method to read the text file "verber.txt" using delimitted format, see the first line of the file for more details
   * */
                      
  private void readVerbsFromFile()
  {
    int numberOfLines = -1;
    String line = null;
    String line2 = null;
    

    // try to do the following
    try {

      // create the buffered reader
      BufferedReader reader2 =
        new BufferedReader(new FileReader(fileNameOfVerbs));

      
      
      while((line2 = reader2.readLine()) != null)
      { 
        numberOfLines++;
      }
      
      strArrayOfVerbs = new String[numberOfLines];
      
      BufferedReader reader =
        new BufferedReader(new FileReader(fileNameOfVerbs));
      
      int i = -1;
      
      while((line = reader.readLine()) != null)
      {
        if(i == -1)
        {
          i++;
          continue;
        }
        
        int beginIndexInString = line.indexOf('\t') + 1;
        int endIndexInString = line.indexOf('\t', beginIndexInString);
        
        if(endIndexInString < 1 || beginIndexInString < 0)
        {
          continue;
        }
        line = line.substring(beginIndexInString, endIndexInString);
        
          
        strArrayOfVerbs[i] = line;
        i++;
      }
      
    } catch(FileNotFoundException ex) 
    {
      System.out.println("Error: file not found");
    } 
    catch(Exception ex) {
      System.out.println("unknown error");
      ex.printStackTrace();
    }
  }
  
  /** Method to read the text file "substantiver.txt" using delimitted format, see the first line of the file for more details
   * */
  
  private void readSubstantivesFromFile()
  {
    int numberOfLines = -1;
    String line = null;

    // try to do the following
    try {

      // create the buffered reader
      BufferedReader reader2 =
        new BufferedReader(new FileReader(fileNameOfSubstantives));

      
      
      while((line = reader2.readLine()) != null)
      { 
        numberOfLines++;
      }
      
      strArrayOfSubstantives = new String[numberOfLines];
      
      BufferedReader reader =
        new BufferedReader(new FileReader(fileNameOfSubstantives));
      
      int i = -1;
      
      while((line = reader.readLine()) != null)
      {
        if(i == -1)
        {
          i++;
          continue;
        }
        
        int beginIndexInString = line.indexOf('\t') + 1;
        int endIndexInString = line.indexOf('\t', beginIndexInString);
        if(endIndexInString < 1 || beginIndexInString < 0)
        {
          continue;
        }
        line = line.substring(beginIndexInString, endIndexInString);
          
        strArrayOfSubstantives[i] = line;
        i++;
      }
      
    } catch(FileNotFoundException ex) 
    {
      System.out.println("Error: file not found");
    } 
    catch(Exception ex) {
      System.out.println("unknown error");
      ex.printStackTrace();
    }
  }
  
  /** Method to read the text file "adjektiver.txt" using delimitted format, see the first line of the file for more details
   * */
  
  private void readAdjectivesFromFile()
  {
    int numberOfLines = -1;
    String line = null;

    // try to do the following
    try {

      // create the buffered reader
      BufferedReader reader2 =
        new BufferedReader(new FileReader(fileNameOfAdjectives));

      
      
      while((line = reader2.readLine()) != null)
      { 
        numberOfLines++;
      }
      
      strArrayOfAdjectives = new String[numberOfLines];
      
      BufferedReader reader =
        new BufferedReader(new FileReader(fileNameOfAdjectives));
      
      int i = -1;
      
      while((line = reader.readLine()) != null)
      {
        if(i == -1)
        {
          i++;
          continue;
        }
        
        int beginIndexInString = line.indexOf('\t') + 1;
        int endIndexInString = line.indexOf('\t', beginIndexInString);
        if(endIndexInString < 1 || beginIndexInString < 0)
        {
          System.out.println("oh dear");
          continue;
        }
        line = line.substring(beginIndexInString, endIndexInString);
          
        strArrayOfAdjectives[i] = line;
        i++;
      }
      
    } catch(FileNotFoundException ex) 
    {
      System.out.println("Error: file not found");
    } 
    catch(Exception ex) {
      System.out.println("unknown error");
      ex.printStackTrace();
    }
  }
  
  /** Method to get the substantives as a String array
    * @return an array of the substantives
    * */
  
  public String[] getStringArrayWithSubstantives()
  {
    return strArrayOfSubstantives;
  }
  
  /** Method to get the adjectives as a String array
    * @return an array of the adjectives
    * */
  
  public String[] getStringArrayWithAdjectives()
  {
    return strArrayOfAdjectives;
  }
  
  /** Method to get the verbs as a String array
    * @return an array of the verbs
    * */
  
  public String[] getStringArrayWithVerbs()
  {
    return strArrayOfVerbs;
  }
}